import 'package:flutter/material.dart';
import 'package:flutter_boss_mine/pages/position_tabbar_page.dart';
import 'package:flutter_boss_mine/utils/color_util.dart';
import 'package:flutter_boss_mine/widget/tag_button.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:random_color/random_color.dart';

final MySelectPosition = ["iOS","Android","Web移动端"];
TabController _controller;


class PositionPage extends StatefulWidget {
  @override
  _PositionPageState createState() => _PositionPageState();
}

class _PositionPageState extends State<PositionPage> with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
  String _currentSelectedValue = "推荐";
  @override
  void initState() {
    _controller = TabController(length: MySelectPosition.length, vsync: this);
    super.initState();
  }
  @override
  bool get wantKeepAlive => true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Column(
          children: [
            _appBar(),
            _fliterView(),
            _tabBarView()
          ],
        ),

      )
    );
  }

  _appBar() {
    return Container(
      width: double.infinity,
      color: ColorUtil.color("#23ACA8"),
      // height: 200.w,
      child: SafeArea(
        child: Stack(
          children: [
            Container(
              height: 130.w,
              width: 0.7.sw,
              child: TabBar(
                indicatorColor: Colors.transparent,
                isScrollable: true,
                labelStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 22),
                unselectedLabelStyle: TextStyle(fontSize: 18, color: Colors.white60),
                controller: _controller,
                tabs: MySelectPosition.map((e) {
                  return Tab(text: e,);
                }).toList()
              )
            ),
            Positioned(
              right: 0,
              bottom: 0,
              top: 0,
              child: Container(
                alignment: Alignment.center,
                width: 0.3.sw,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    IconButton(icon: Icon(Icons.add, color: Colors.white, size: 32)),
                    Container(color: Colors.white60, width: 1, height: 15,),
                    IconButton(icon: Icon(Icons.search, color: Colors.white, size: 32)),
                  ],
                ),
              ),
            )
          ],
        )
      )
    );
  }

  _fliterView() {
    return Stack(
      children: [
        Container(
          width: double.infinity,
          color: Colors.white,
          height: 50,
          child: Row(
            // mainAxisAlignment: MainAxisAlignment.start,
            // crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              _filterButton("推荐"),
              _filterButton("附近"),
              _filterButton("最新"),
              TagButton("沈阳"),
              TagButton("筛选"),
              TagButton("关键词"),
            ],
          ),
        ),
        Positioned(
          left: 20,
          right: 20,
          bottom: 0,
          child: Container(height: .5, width: 0.8.sw, color: Colors.grey,),
        )
      ],
    );
  }

  _filterButton(String title) {
    return ButtonTheme(
      minWidth: 30,
      child: RaisedButton(
        textColor: _currentSelectedValue == title?Colors.black:Colors.grey,
        onPressed: () {
          print("点击了"+title);
          setState(() {
            _currentSelectedValue = title;
          });
        },
        color: Colors.white,
        child: Text(title),
        elevation: 0,
        splashColor: Colors.transparent,
        highlightColor: Colors.transparent,
        hoverColor: Colors.transparent,
        highlightElevation: 0,
      ),
    );
  }


  _tabBarView() {
    return Flexible(
      child: TabBarView(
        controller: _controller,
        children: MySelectPosition.map((e){
          return PositionTabbarPage();
        }).toList(),

      ),
    );
  }
}

/**
 *
 *
*/